package day19.zhiyou100;

import java.util.Timer;
import java.util.TimerTask;

public class TimerDemo {
    public static void main(String[] args) {
        // 定时器每隔三秒值打印下"我还活着" 延迟5秒钟
        // Timer
        Timer timer = new Timer();// 定时器对象创建
        timer.schedule(new TimerTask() {
            int  count = 0;
            @Override
            public void run() {
                System.out.println("我还活着!!!");
                count++;
                if (count == 10) {
                    //timer.cancel();
                    System.exit(0);// 停止虚拟机程序  0代表状态码
                }
            }
        },5000,3000);
    }

}
